from os import name
from typing import Mapping
import requests
import time

headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36',
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
    }
cookies = {
        'Cookie':'sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross={"distinct_id":"17a6602b4cf558-045d7d6971c1de-c3f3568-2073600-17a6602b4d0393","first_id":"","props":{},"$device_id":"17a6602b4cf558-045d7d6971c1de-c3f3568-2073600-17a6602b4d0393"}; SESSION=e95e3982a6604f5a8c1da876b5b03636'
}


def get_yzm():
    t = int(time.time()*1000)
    url = 'https://www.sf-express.com/sf-service-owf-web/service/captcha/sms?force=true&time={}'.format(t)
    response = requests.get(url,headers=headers,cookies=cookies)
    with open('yzm.png','wb') as f:
        f.write(response.content)


def send_code():
    code = input('请输入验证码:')
    url = 'https://www.sf-express.com/sf-service-owf-web/service/sms/user/18718896370/notification?app=sms&answer={}&area=&lang=sc&region=cn&translate='.format(code)
    response = requests.post(url,headers=headers,cookies=cookies)
    print(response.text)


def login():
    url = 'https://www.sf-express.com/sf-service-core-web/service/user/sms/login?rememberMe=true&lang=sc&region=cn&translate='
    code = input('请输入短信验证码:')
    headers['SMS-Verification-Mobile'] = '18718896370'
    headers['SMS-Verification-App'] = 'user'
    headers['SMS-Verification-Code'] = code
    response = requests.post(url,headers=headers,cookies=cookies)
    print(response.text)


if __name__ == "__main__":
    get_yzm()
    send_code()
    login()